﻿
@{
    ViewBag.Title = "密码修改";
    Layout = "~/Views/Shared/_LayoutPageExpertsManagement.cshtml";
}
<link href="~/Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/css/base.css" rel="stylesheet" />
<h3 class="text-center">修改登陆密码</h3>
<div class="container-fluid">
    <form>
        <div class="form-group">
            <label class="control-label">当前密码<span class="text-danger">*</span></label>
            <div class="controls">
                <input class="form-control" type="password" placeholder="请输入当前使用的密码" id="inputpwd" />
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">新密码<span class="text-danger">*</span></label><div class="controls">
                <input class="form-control" type="password" placeholder="请输入新的密码" id="inputnewpwd" />
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">重复密码<span class="text-danger">*</span></label><div class="controls">
                <input class="form-control" type="password" placeholder="请再一次输入新的密码" id="inputagainpwd" />
            </div>
        </div>
        <p>注：只能由数字、字母、下划线组成且长度8-16位！</p>

    </form>
    <div class="pager">
        <input class="btn btn-primary" type="button" value="确认" title="点击确定更改密码" id="btnsave" />
        <input class="btn btn-danger" type="button" value="取消" title="点击取消返回专家列表" id="btncancel" />
    </div>
</div>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
    !window.jQuery || document.write("<script src='/Scripts/jquery-2.1.4.min.js'><" + '/' + "script>");
</script>
<script>

    $(function () {
        //$("#inputnewpwd").blur(function () {
        //    var newpwd = $.trim($(this).val());
        //    if (EmptyCheck(newpwd)) {
        //        alert("您设置的新密码不能为空！")
        //    } else if (newpwd.length < 7 || newpwd.length > 15) { alert("新密码的长度应该限制在8-16位！"); }
        //    else if (!checkpwd(newpwd)) { alert("您输入的新密码格式有误，请核对后重新输入！"); } else {
        //        return false;
        //    }
        //});
        //$("#inputagainpwd").blur(function () {
        //    var newpwd = $.trim($("#inputnewpwd").val());
        //    var againpwd = $.trim($(this).val());
        //    if (EmptyCheck(againpwd)) {
        //        alert("请您再次输入新密码！");
        //    } else if (againpwd != newpwd) {
        //        alert("您两次输入的密码不一致！");
        //    } else {
        //        return false;
        //    }
        //});
        $("#btnsave").click(function () {
            var pwd = $.trim($("#inputpwd").val());
            var newpwd = $.trim($("#inputnewpwd").val());
            var againpwd = $.trim($("#inputagainpwd").val());
            if (EmptyCheck(pwd)) { alert("请输入当前账户使用的密码！") }
            else if (EmptyCheck(newpwd)) { alert("您设置的新密码不能为空！") }
            else if (EmptyCheck(againpwd)) { alert("请您再次输入新密码！"); }
            else if (newpwd.length < 7 || newpwd.length > 15 || !checkpwd(newpwd)) { alert("您输入的新密码格式有误，请核对后重新输入！"); }
            else if (newpwd != againpwd) { alert("您两次输入的密码不一致！"); }
            else {
                $.ajax({
                    type: "POST",
                    url: "/Backstage/ValidatePassword",
                    data: { "pwd": pwd, "newpwd": newpwd },
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 'ok') {
                            alert(data.msg);
                            window.location = "/Backstage/Login";
                        }
                        else {
                            alert(data.msg);
                        }
                    },
                    error: function (xhr) {
                        alert("保存失败，请稍后重试！当前请求的状态为:" + xhr.readyState);
                    }
                });
            }
        });
        $("#btncancel").click(function () {
            if (confirm("您确定要取消保存吗？")) {
                window.location = "/ExpertsManage/Index";
            } else { return false; }
        });
    });

    function checkpwd(data) {
        var pwdReg = /^[a-zA-Z0-9_-]{8,16}$/;
        return pwdReg.test(data);
    }

    function EmptyCheck(data) {
        if (data == null || data.length == 0) {
            return true;
        } else {
            return false;
        }
    }
</script>